<template>
	<view>
		<view class="u-flex">
			<view style="width: 30%;" class="u-p-10 u-text-center" @click="tocheng">位置：{{dizhi}}</view>
			<view style="width: 70%;">
				<uni-search-bar placeholder="搜索新闻" @confirm="shou"></uni-search-bar>
			</view>
		</view>
		<u-swiper :height="250" :list="lun" :effect3d="true" :interval="3000" @click="dianxin(50)">
		</u-swiper>
		<uni-group title="全部服务">
			<view class="item-container">
				<view class="thumb-box" v-for="(item1, index1) in fen" :key="index1">
					<image class="item-menu-image" :src="base+item1.imgUrl" mode=""></image>
					<view class="item-menu-name">{{item1.serviceName}}</view>
					
				</view>
				<view class="thumb-box" >
					<image class="item-menu-image" src="../../../static/icons/baoyu.png" @click="quan" mode=""></image>
					<view class="item-menu-name">全部服务</view>
					
				</view>
			</view>
		</uni-group>
		<uni-group title="推荐新闻">
			<view  class="u-flex" style="justify-content: space-between;">
				<view v-for="(item,index) in tui" style="width:48%;" @click="dianxin(item.id)">
					<image :src="base+item.cover" mode="aspectFill" style="height: 200rpx;width: 100%;border-radius: 15rpx;"></image>
					<view>{{fillstr(item.title)}}</view>
				</view>
			</view>
		</uni-group>
		<uni-group>
			<scroll-view :scroll-x="true" style="white-space: nowrap;" class="u-border-bottom u-border-top">
				<view @click="tixian(item.id,index)" v-for="(item,index) in fen1" :style="{'backgroundColor':yan[index]}" style="padding: 30rpx;width: 30%;text-align: center;display:inline-block;">{{item.name}}</view>
			</scroll-view>
		</uni-group>
		<uni-group>
			<view v-for="(item,index) in news">
				<uni-card  v-if="index%2==0" :title="item.title" @click="dianxin(item.id)" >
					<image :src="base+item.cover" style="width: 100%;"></image>
					<view v-html="fillstr(item.content)"></view>
					<view>评论数：{{item.commentNum}}</view>
					<view>发布时间：{{item.publishDate}}</view>
				</uni-card>
				<uni-card v-if="index%2!=0" :title="item.title" :thumbnail="base+item.cover"  @click="dianxin(item.id)" >
					<view v-html="fillstr(item.content)"></view>
					<view>评论数：{{item.commentNum}}</view>
					<view>发布时间：{{item.publishDate}}</view>
				</uni-card>
			</view>
		</uni-group>
	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				yan:[],
				dizhi:'',
				base: api.baseurl,
				lun: [],
				fen:[],
				tui:[],
				fen1:[],
				news:[],
				iid:[]
			}
		},
		onShow() {
			let chen = uni.getStorageSync('chen')
			console.log(chen)
			if(chen != ''){
				this.dizhi = chen
			}else{
				this.dizhi = '大连'
			}
			this.getlun()
			this.getfem()
			this.gettui()
			this.getquan()
			this.getxin(9)
		},
		methods: {
			tocheng(){
				uni.navigateTo({
					url:'chen'
				})
			},
			dianxin(id){
				uni.navigateTo({
					url:'xinwen?id='+id
				})
			},
			quan(){
				uni.switchTab({
					url:'../allserver/allserver'
				})
			},
			shou(e){
				uni.navigateTo({
					url:'list?name='+e.value
				})
			},
			tixian(id,index){
				this.yan = []
				this.yan[index] = '#DBF1E1'
				this.getxin(id)
			},
			getxin(id){
				this.$get(this.base + '/prod-api/press/press/list',{
					type:id
				}).then((res) => {
					this.news = res.rows
				})
			},
			getquan(){
				this.$get(this.base + '/prod-api/press/category/list').then((res) => {
					this.fen1 = res.data
				})
			},
			fillstr(str){
				return str.length > 16?str.substring(0,14)+'...':str
			},
			getlun() {
				this.yan = []
				this.yan[0] ='#DBF1E1'
				this.lun  =[]
				this.$get(this.base + '/prod-api/api/rotation/list').then((res) => {
					res.rows.forEach((item) => {
						this.lun.push({
							image: this.base + item.advImg
						})
					})
				})
			},
			getfem() {
				this.$get(this.base + '/prod-api/api/service/list').then((res) => {
					this.fen = res.rows.slice(0,9)
				})
			},
			gettui() {
				this.$get(this.base + '/prod-api/press/press/list',{
					hot:'Y'
				}).then((res) => {
					this.tui = res.rows
					console.log(this.tui)
				})
			},
		}
	}
</script>

<style>
	.dian:hover{
		background-color: #DBF1E1;
	}
	.item-container {
			display: flex;
			flex-wrap: wrap;
		}
	
		.thumb-box {
			width: 20%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin-top: 20rpx;
		}
	
		.item-menu-image {
			width: 80rpx;
			height: 80rpx;
		}
</style>
